package com.frank.service.test4;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;

/**
 * @Author: huweifeng
 * @Date: 2024/12/13
 * @Description: NIO创建client
 **/
@Slf4j
public class Client {
    public static void main(String[] args) throws IOException {
        // 创建客户端
        SocketChannel sc = SocketChannel.open();
        sc.connect(new InetSocketAddress("localhost",8000));
        sc.write(StandardCharsets.UTF_8.encode("1325\n"));
        sc.write(StandardCharsets.UTF_8.encode("abc\n"));
        System.out.println("waiting...");
        // 最后断开
        sc.close();
    }
}
